package com.poi.qianmi.fetch.demo1;

import com.poi.qianmi.conver.UserConver;
import com.poi.qianmi.model.User;
import com.poi.qianmi.path.GlobalPath;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname Fetch1Application
 * @Description 读取方式1，常规读取
 * @Date 2019/9/19 7:32 下午
 * @Created by xiaocai
 */
public class Fetch1Main {

    @SneakyThrows
    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();

        List<User> userList = new ArrayList<User>();
        File file = new File(GlobalPath.getInstance(20));
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook(new FileInputStream(file));
        //获得第一个sheet页
        XSSFSheet sheet = hssfWorkbook.getSheetAt(0);
        for (Row row : sheet) {
            User user = UserConver.converterTosheet(row);
            userList.add(user);
        }
        Thread.sleep(10000);
        long endTime = System.currentTimeMillis();
        System.out.println("处理数据条数：" + userList.size() + " 条");
        System.out.println("程序运行时间： " + (endTime - startTime) + "ms");

    }
}
